﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using CMS.BLL;

public partial class Controls_Galleries_ctrGalleryList_Homepage : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.InitData();
            this.BindData();
        
        }
    }
    private void InitData()
    {
        int nCurrentLanguage = Support.GetCurrentLanguage();

        lnkGallery.Text = MultipleLanguage.GALLERY[nCurrentLanguage -1];
        lnkGallery.NavigateUrl = Config.ROOT + Pages.FrontEnds.GALLERY;
       
    }

    private void BindData()
    {
        int nPageCount = 0;
        Albums objAlbum = new Albums();
        DataTable dtbAlbum = new DataTable();
        dtbAlbum = objAlbum.Search(6, "", 1, 6, ref nPageCount);
        dtlGalleries.DataSource = dtbAlbum;
        dtlGalleries.DataBind();
    }

    protected void dtlGalleries_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        int nCurentLang = Support.GetCurrentLanguage(); 
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            ImageButton btnImage = (ImageButton)e.Item.FindControl("btnImage");

            btnImage.ImageUrl = Config.ROOT + Config.IMAGE_GALLERY_DEFAULT_UPLOAD + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "AlbumImage"));
            btnImage.CommandArgument = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "AlbumID"));
            switch (nCurentLang )
                {
                case 1:
                      btnImage.ToolTip=ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "AlbumName1"));
                    break;
                case 2:
                      btnImage.ToolTip=ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "AlbumName2"));
                    break;
                case 3:
                      btnImage.ToolTip=ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "AlbumName3"));
                    break;
            }
        }
    }
    protected void dtlGalleries_ItemCommand(object source, DataListCommandEventArgs e)
    {
        string sCommand = e.CommandName;
        int nAlbumID = ConvertData.ConvertToInt(e.CommandArgument);
        switch (sCommand)
        {
            case "image":
                string sAlbumDetail = Config.ROOT + Pages.FrontEnds.GALLERY + "?" + Config.ALBUM_ID + "=" + nAlbumID;
                Response.Redirect(sAlbumDetail);
                break;
        }
    }
}
